package ro.prjmanager.core.service;

import ro.prjmanager.core.dao.GenericDAO;

import java.io.Serializable;
import java.util.List;

public abstract class AbstractService<M,ID extends Serializable> implements Service<M,ID> {
    protected GenericDAO<M,ID> dao;

    public GenericDAO<M, ID> getDao() {
        return dao;
    }

    public void setDao(GenericDAO<M, ID> dao) {
        this.dao = dao;
    }

    public M load(ID id){
         return dao.find(id,false);
    }

    public List<M> listPag(int startPage, int resPerPage) {
        return dao.listPag(startPage, resPerPage);
    }

    public List<M> listPag(int startPage, int resPerPage, String orderCol, boolean asc, Object... otherItems) {
        return dao.listPag(startPage, resPerPage,orderCol, asc, otherItems);
    }

    public List<M> list() {
        return dao.findAll();
    }

    public List<M> listPagFilter(int startPage, int resPerPage, String filter) {
        return dao.listPagFilter(startPage, resPerPage,filter);
    }

    public List<M> listPag(SQLQuery sqlQuery){
       return dao.listPag(sqlQuery);
    }

    public int no(String filter) {
        return dao.no(filter);
    }

    public int no(SQLQuery sqlQuery) {
        return dao.no(sqlQuery);
    }



    public void update(M entity) {
        dao.update(entity);
    }

    public void create(M entity) {
        dao.create(entity);
    }

    public void delete(ID id) {
        M entity=dao.find(id,false);
        dao.delete(entity);
    }

}

